#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>

int main(){
  int fd[2];                                
  char buffer[] = "我就是魔法少女TERIRI!";  
  char readbuffer[30]={0};
  if(pipe(fd) < 0){                         
    perror("pipe");                         
  }                                         
  write(fd[1], buffer, 30);
  close(fd[1]);
  //写端关闭, 如果管道中有数据是可以读的
  if(read(fd[0],readbuffer, 30) == 0){     
    perror("read");
    return 0;
  }
  printf("%s\n", readbuffer);
  if(read(fd[0],readbuffer, 30) == 0){     
    perror("read");
    return 0;
  }
  return 0;
}
